#include "document.h"
#include <QDebug>

DocumentRow::DocumentRow(QObject *parent) :
    QObject(parent)
{

}

Document::Document(QObject *parent):
    QObject(parent)
{
//    ID = id;
//    type = t;
//    number = n;
//    client = c;
//    date = d;
//    status = s;


//    model_document_row = new QSqlRelationalTableModel();
//    model_document_row->setTable("document_row");
//    model_document_row->setFilter("document="+QString().number(ID));
//    model_document_row->select();

//    const int nRowNum = model_document_row->rowCount();
//    for (int i = 0; i < nRowNum; ++i)  //цикл по строкам таблицы
//    {
//        QSqlRecord oSqlRecord = model_document_row->record(i);
//        int id = oSqlRecord.value(0).toInt();
//        rows.insert(id,new DocumentRow);
//        rows[id]->ID = oSqlRecord.value(0).toInt();
//        rows[id]->product = oSqlRecord.value(1).toInt();
//        rows[id]->qty = oSqlRecord.value(2).toInt();
//        rows[id]->price = oSqlRecord.value(3).toDouble();
//        rows[id]->amount = rows[id]->qty * rows[id]->price;

//        qDebug() <<rows[id]->amount;
//   }
//    qDebug() << model_document_row->data(model_document_row->index(0,4)).toString();

}

void Document::changeRow(int id,int product,int qty, double price)
{
    this->rows[id]->product = product;
    this->rows[id]->qty = qty;
    this->rows[id]->price = price;
    this->total = this->total - this->rows[id]->amount;
    this->rows[id]->amount = qty * price;
    this->total = this->total + this->rows[id]->amount;

 }
